package nongchang.kuaijiecaifu.com.ncapp_android;

import android.content.Context;

import com.google.gson.Gson;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.umeng.analytics.AnalyticsConfig;
import com.umeng.analytics.MobclickAgent;
import com.umeng.update.UmengUpdateAgent;

import ezy.lite.util.Device;
import ezy.lite.util.Prefs;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.data.HomeCartManager;

/**
 * Created by Administrator on 2016/6/21 0021.
 */
public class Global {
    public final static Gson gson = new Gson();
    private static HomeCartManager _homecartManager;
    public static HomeCartManager get_homecartManager(){
        if (_homecartManager == null) {
            String s = Prefs.get(Const.CART_INFO, "");
            if (s.length() < 1) {
                _homecartManager = new HomeCartManager();
            } else {
                _homecartManager = gson.fromJson(s, HomeCartManager.class);
            }
        }
        return _homecartManager;
    }
    public static  void set_homecartManager(HomeCartManager homecartManager){
        _homecartManager = homecartManager;
        Prefs.apply(Const.CART_INFO, (homecartManager == null) ? "" : gson.toJson(homecartManager));
    }

    public static Context context;

    public static void init(Context context) {

        Context ctx = Global.context = context.getApplicationContext();

//        Device.init(ctx);
        Prefs.init(ctx);
        FlowManager.init(ctx);



        MobclickAgent.setDebugMode(false);
        MobclickAgent.setCatchUncaughtExceptions(true);



        //LeakCanary.install(this);

        UmengUpdateAgent.update(ctx);
    }
}
